--
-- PostgreSQL database dump
--

-- Dumped from database version 8.4.0
-- Dumped by pg_dump version 9.0.0
-- Started on 2012-05-03 17:41:57

SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;

--
-- TOC entry 1892 (class 1262 OID 90065)
-- Dependencies: 1891
-- Name: stock; Type: COMMENT; Schema: -; Owner: stock
--

COMMENT ON DATABASE stock IS 'Esta es la Base de datos del Proyecto Stock de Eirete';


--
-- TOC entry 343 (class 2612 OID 16386)
-- Name: plpgsql; Type: PROCEDURAL LANGUAGE; Schema: -; Owner: postgres
--

CREATE OR REPLACE PROCEDURAL LANGUAGE plpgsql;


ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;

SET search_path = public, pg_catalog;

--
-- TOC entry 21 (class 1255 OID 90422)
-- Dependencies: 343 6
-- Name: producto_update_tr(); Type: FUNCTION; Schema: public; Owner: stock
--

CREATE FUNCTION producto_update_tr() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
  id_producto_au BIGINT;
  cantidad_anterior_au BIGINT;
  cantidad_posterior_au BIGINT;
  precio_anterior_au BIGINT;
  precio_posterior_au BIGINT;
BEGIN
	IF (TG_OP = 'UPDATE' ) THEN

		id_producto_au := OLD.id;
		cantidad_anterior_au := OLD.cantidad;
		cantidad_posterior_au := NEW.cantidad;
		precio_anterior_au := OLD.precio;
		precio_posterior_au := NEW.precio;  
        
        insert into auditoria_producto(id_producto,cantidad_anterior,cantidad_posterior,precio_anterior,precio_posterior,motivo)
		values (id_producto_au,cantidad_anterior_au,cantidad_posterior_au,precio_anterior_au,precio_posterior_au, 'ACTUALIZACION');         
		RETURN NULL;
            
	END IF;

END;

/*TG_OP puede ser INSERT, UPDATE OR DELETE*/
$$;


ALTER FUNCTION public.producto_update_tr() OWNER TO stock;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- TOC entry 1548 (class 1259 OID 90428)
-- Dependencies: 6
-- Name: auditoria_cliente; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE auditoria_cliente (
    id bigint NOT NULL,
    id_cliente bigint NOT NULL,
    telefono_anterior character varying NOT NULL,
    telefono_posterior character varying NOT NULL,
    email_anterior character varying NOT NULL,
    email_posterior character varying NOT NULL
);


ALTER TABLE public.auditoria_cliente OWNER TO stock;

--
-- TOC entry 1895 (class 0 OID 0)
-- Dependencies: 1548
-- Name: TABLE auditoria_cliente; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE auditoria_cliente IS 'Tabla que contiene todas las auditorias de los clientes.';


--
-- TOC entry 1549 (class 1259 OID 90434)
-- Dependencies: 1548 6
-- Name: auditoria_cliente_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE auditoria_cliente_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.auditoria_cliente_id_seq OWNER TO stock;

--
-- TOC entry 1896 (class 0 OID 0)
-- Dependencies: 1549
-- Name: auditoria_cliente_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE auditoria_cliente_id_seq OWNED BY auditoria_cliente.id;


--
-- TOC entry 1897 (class 0 OID 0)
-- Dependencies: 1549
-- Name: auditoria_cliente_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('auditoria_cliente_id_seq', 1, false);


SET default_with_oids = true;

--
-- TOC entry 1547 (class 1259 OID 90395)
-- Dependencies: 6
-- Name: auditoria_producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE auditoria_producto (
    id bigint NOT NULL,
    id_producto bigint NOT NULL,
    cantidad_anterior bigint NOT NULL,
    cantidad_posterior bigint NOT NULL,
    precio_anterior bigint NOT NULL,
    precio_posterior bigint NOT NULL,
    motivo character varying NOT NULL
);


ALTER TABLE public.auditoria_producto OWNER TO stock;

--
-- TOC entry 1898 (class 0 OID 0)
-- Dependencies: 1547
-- Name: TABLE auditoria_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE auditoria_producto IS 'Esta tabla es para la auditoria de producto.';


--
-- TOC entry 1899 (class 0 OID 0)
-- Dependencies: 1547
-- Name: COLUMN auditoria_producto.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.id IS 'Identificador de la Auditoria Producto.';


--
-- TOC entry 1900 (class 0 OID 0)
-- Dependencies: 1547
-- Name: COLUMN auditoria_producto.id_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.id_producto IS 'Identificador del Producto';


--
-- TOC entry 1901 (class 0 OID 0)
-- Dependencies: 1547
-- Name: COLUMN auditoria_producto.cantidad_anterior; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.cantidad_anterior IS 'Cantidad Anterior';


--
-- TOC entry 1902 (class 0 OID 0)
-- Dependencies: 1547
-- Name: COLUMN auditoria_producto.cantidad_posterior; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.cantidad_posterior IS 'Cantidad Posterior';


--
-- TOC entry 1903 (class 0 OID 0)
-- Dependencies: 1547
-- Name: COLUMN auditoria_producto.precio_anterior; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.precio_anterior IS 'Precio Anterior';


--
-- TOC entry 1904 (class 0 OID 0)
-- Dependencies: 1547
-- Name: COLUMN auditoria_producto.precio_posterior; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.precio_posterior IS 'Precio Posterior';


--
-- TOC entry 1905 (class 0 OID 0)
-- Dependencies: 1547
-- Name: COLUMN auditoria_producto.motivo; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN auditoria_producto.motivo IS 'Motivo de Auditoria.';


--
-- TOC entry 1546 (class 1259 OID 90393)
-- Dependencies: 1547 6
-- Name: auditoria_producto_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE auditoria_producto_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.auditoria_producto_id_seq OWNER TO stock;

--
-- TOC entry 1906 (class 0 OID 0)
-- Dependencies: 1546
-- Name: auditoria_producto_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE auditoria_producto_id_seq OWNED BY auditoria_producto.id;


--
-- TOC entry 1907 (class 0 OID 0)
-- Dependencies: 1546
-- Name: auditoria_producto_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('auditoria_producto_id_seq', 5, true);


--
-- TOC entry 1530 (class 1259 OID 90066)
-- Dependencies: 6
-- Name: tipo_producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE tipo_producto (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    descripcion character varying NOT NULL
);


ALTER TABLE public.tipo_producto OWNER TO stock;

--
-- TOC entry 1908 (class 0 OID 0)
-- Dependencies: 1530
-- Name: TABLE tipo_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE tipo_producto IS 'En esta tabla se tiene que administrar todas las categorias de Producto.';


--
-- TOC entry 1909 (class 0 OID 0)
-- Dependencies: 1530
-- Name: COLUMN tipo_producto.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN tipo_producto.id IS 'Identificador de la Categoria.';


--
-- TOC entry 1910 (class 0 OID 0)
-- Dependencies: 1530
-- Name: COLUMN tipo_producto.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN tipo_producto.nombre IS 'Nombre de la Categoría.';


--
-- TOC entry 1911 (class 0 OID 0)
-- Dependencies: 1530
-- Name: COLUMN tipo_producto.descripcion; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN tipo_producto.descripcion IS 'Descripción del Tipo de Producto.';


--
-- TOC entry 1531 (class 1259 OID 90072)
-- Dependencies: 6 1530
-- Name: categoria_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE categoria_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.categoria_id_seq OWNER TO stock;

--
-- TOC entry 1912 (class 0 OID 0)
-- Dependencies: 1531
-- Name: categoria_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE categoria_id_seq OWNED BY tipo_producto.id;


--
-- TOC entry 1913 (class 0 OID 0)
-- Dependencies: 1531
-- Name: categoria_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('categoria_id_seq', 17, true);


--
-- TOC entry 1541 (class 1259 OID 90292)
-- Dependencies: 6
-- Name: cliente; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE cliente (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    apellido character varying NOT NULL,
    telefono character varying NOT NULL,
    nro_doc character varying NOT NULL,
    direccion character varying NOT NULL,
    email character varying NOT NULL
);


ALTER TABLE public.cliente OWNER TO stock;

--
-- TOC entry 1914 (class 0 OID 0)
-- Dependencies: 1541
-- Name: TABLE cliente; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE cliente IS 'En esta tabla se tiene que administrar todos los clientes del Sistema.';


--
-- TOC entry 1915 (class 0 OID 0)
-- Dependencies: 1541
-- Name: COLUMN cliente.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.id IS 'Identificador del Cliente.';


--
-- TOC entry 1916 (class 0 OID 0)
-- Dependencies: 1541
-- Name: COLUMN cliente.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.nombre IS 'Nombre del Cliente.';


--
-- TOC entry 1917 (class 0 OID 0)
-- Dependencies: 1541
-- Name: COLUMN cliente.apellido; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.apellido IS 'Apellido del Cliente.';


--
-- TOC entry 1918 (class 0 OID 0)
-- Dependencies: 1541
-- Name: COLUMN cliente.telefono; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.telefono IS 'Telefono del Cliente.';


--
-- TOC entry 1919 (class 0 OID 0)
-- Dependencies: 1541
-- Name: COLUMN cliente.nro_doc; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.nro_doc IS 'Nro. Documento del cliente.';


--
-- TOC entry 1920 (class 0 OID 0)
-- Dependencies: 1541
-- Name: COLUMN cliente.direccion; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.direccion IS 'Direccion del Cliente.';


--
-- TOC entry 1921 (class 0 OID 0)
-- Dependencies: 1541
-- Name: COLUMN cliente.email; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN cliente.email IS 'Email del Cliente.';


--
-- TOC entry 1540 (class 1259 OID 90290)
-- Dependencies: 1541 6
-- Name: cliente_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE cliente_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.cliente_id_seq OWNER TO stock;

--
-- TOC entry 1922 (class 0 OID 0)
-- Dependencies: 1540
-- Name: cliente_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE cliente_id_seq OWNED BY cliente.id;


--
-- TOC entry 1923 (class 0 OID 0)
-- Dependencies: 1540
-- Name: cliente_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('cliente_id_seq', 1, false);


--
-- TOC entry 1543 (class 1259 OID 90308)
-- Dependencies: 6
-- Name: compra; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE compra (
    id bigint NOT NULL,
    id_producto_comprado bigint NOT NULL,
    cantidad_comprada bigint NOT NULL,
    monto_compra bigint NOT NULL,
    id_usuario_catastrador bigint NOT NULL,
    fecha_compra timestamp without time zone NOT NULL
);


ALTER TABLE public.compra OWNER TO stock;

--
-- TOC entry 1924 (class 0 OID 0)
-- Dependencies: 1543
-- Name: TABLE compra; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE compra IS 'En esta tabla se tiene que administrar la compra de todos los productos que se realiza sobre el Sistema.';


--
-- TOC entry 1925 (class 0 OID 0)
-- Dependencies: 1543
-- Name: COLUMN compra.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.id IS 'Identificador de la Compra.';


--
-- TOC entry 1926 (class 0 OID 0)
-- Dependencies: 1543
-- Name: COLUMN compra.id_producto_comprado; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.id_producto_comprado IS 'Identificador del Producto Comprado.';


--
-- TOC entry 1927 (class 0 OID 0)
-- Dependencies: 1543
-- Name: COLUMN compra.cantidad_comprada; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.cantidad_comprada IS 'Cantidad de Compra.';


--
-- TOC entry 1928 (class 0 OID 0)
-- Dependencies: 1543
-- Name: COLUMN compra.monto_compra; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.monto_compra IS 'Monto de la Compra.';


--
-- TOC entry 1929 (class 0 OID 0)
-- Dependencies: 1543
-- Name: COLUMN compra.id_usuario_catastrador; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.id_usuario_catastrador IS 'Identificador del Usuario Catastrador.';


--
-- TOC entry 1930 (class 0 OID 0)
-- Dependencies: 1543
-- Name: COLUMN compra.fecha_compra; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN compra.fecha_compra IS 'Fecha de la Compra.';


--
-- TOC entry 1542 (class 1259 OID 90306)
-- Dependencies: 1543 6
-- Name: compra_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE compra_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.compra_id_seq OWNER TO stock;

--
-- TOC entry 1931 (class 0 OID 0)
-- Dependencies: 1542
-- Name: compra_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE compra_id_seq OWNED BY compra.id;


--
-- TOC entry 1932 (class 0 OID 0)
-- Dependencies: 1542
-- Name: compra_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('compra_id_seq', 1, false);


--
-- TOC entry 1532 (class 1259 OID 90095)
-- Dependencies: 6
-- Name: producto; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE producto (
    id bigint NOT NULL,
    codigo character varying NOT NULL,
    nombre character varying NOT NULL,
    id_tipo_producto bigint NOT NULL,
    cantidad bigint NOT NULL,
    precio bigint NOT NULL,
    id_proveedor bigint NOT NULL
);


ALTER TABLE public.producto OWNER TO stock;

--
-- TOC entry 1933 (class 0 OID 0)
-- Dependencies: 1532
-- Name: TABLE producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE producto IS 'En esta tabla se tiene que administrar todos los productos con podrán ser vendidos o comprados.';


--
-- TOC entry 1934 (class 0 OID 0)
-- Dependencies: 1532
-- Name: COLUMN producto.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.id IS 'Identificador del producto';


--
-- TOC entry 1935 (class 0 OID 0)
-- Dependencies: 1532
-- Name: COLUMN producto.codigo; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.codigo IS 'Código del Producto.';


--
-- TOC entry 1936 (class 0 OID 0)
-- Dependencies: 1532
-- Name: COLUMN producto.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.nombre IS 'Nombre del Producto.';


--
-- TOC entry 1937 (class 0 OID 0)
-- Dependencies: 1532
-- Name: COLUMN producto.id_tipo_producto; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.id_tipo_producto IS 'Identificador del Tipo de Producto Asociado.';


--
-- TOC entry 1938 (class 0 OID 0)
-- Dependencies: 1532
-- Name: COLUMN producto.cantidad; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.cantidad IS 'Cantidad en Stock del Producto.';


--
-- TOC entry 1939 (class 0 OID 0)
-- Dependencies: 1532
-- Name: COLUMN producto.precio; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN producto.precio IS 'Precio del Producto.';


--
-- TOC entry 1533 (class 1259 OID 90101)
-- Dependencies: 6 1532
-- Name: producto_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE producto_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.producto_id_seq OWNER TO stock;

--
-- TOC entry 1940 (class 0 OID 0)
-- Dependencies: 1533
-- Name: producto_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE producto_id_seq OWNED BY producto.id;


--
-- TOC entry 1941 (class 0 OID 0)
-- Dependencies: 1533
-- Name: producto_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('producto_id_seq', 23, true);


--
-- TOC entry 1534 (class 1259 OID 90103)
-- Dependencies: 6
-- Name: proveedor; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE proveedor (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    nombre_responsable character varying NOT NULL,
    email_responsable character varying NOT NULL,
    telefono_responsable character varying NOT NULL
);


ALTER TABLE public.proveedor OWNER TO stock;

--
-- TOC entry 1942 (class 0 OID 0)
-- Dependencies: 1534
-- Name: TABLE proveedor; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE proveedor IS 'En esta tabla se tiene que administrar todos los proveedores que venden productos a la empresa.';


--
-- TOC entry 1943 (class 0 OID 0)
-- Dependencies: 1534
-- Name: COLUMN proveedor.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN proveedor.id IS 'Identificador de los Proveedores.';


--
-- TOC entry 1944 (class 0 OID 0)
-- Dependencies: 1534
-- Name: COLUMN proveedor.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN proveedor.nombre IS 'Nombre del Proveedor.';


--
-- TOC entry 1945 (class 0 OID 0)
-- Dependencies: 1534
-- Name: COLUMN proveedor.email_responsable; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN proveedor.email_responsable IS 'Email del Responsable.';


--
-- TOC entry 1535 (class 1259 OID 90109)
-- Dependencies: 6 1534
-- Name: proveedor_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE proveedor_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.proveedor_id_seq OWNER TO stock;

--
-- TOC entry 1946 (class 0 OID 0)
-- Dependencies: 1535
-- Name: proveedor_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE proveedor_id_seq OWNED BY proveedor.id;


--
-- TOC entry 1947 (class 0 OID 0)
-- Dependencies: 1535
-- Name: proveedor_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('proveedor_id_seq', 5, true);


--
-- TOC entry 1536 (class 1259 OID 90111)
-- Dependencies: 6
-- Name: rol; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE rol (
    id bigint NOT NULL,
    nombre character varying NOT NULL,
    descripcion character varying NOT NULL,
    hab_inh character varying(1) NOT NULL
);


ALTER TABLE public.rol OWNER TO stock;

--
-- TOC entry 1948 (class 0 OID 0)
-- Dependencies: 1536
-- Name: TABLE rol; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE rol IS 'En esta tabla se tiene que administrar todos los Roles del Sistema.';


--
-- TOC entry 1949 (class 0 OID 0)
-- Dependencies: 1536
-- Name: COLUMN rol.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN rol.id IS 'Identificador del Rol.';


--
-- TOC entry 1950 (class 0 OID 0)
-- Dependencies: 1536
-- Name: COLUMN rol.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN rol.nombre IS 'Nombre del Rol.';


--
-- TOC entry 1951 (class 0 OID 0)
-- Dependencies: 1536
-- Name: COLUMN rol.descripcion; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN rol.descripcion IS 'Funcion del Rol, actividades que realiza.';


--
-- TOC entry 1952 (class 0 OID 0)
-- Dependencies: 1536
-- Name: COLUMN rol.hab_inh; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN rol.hab_inh IS 'Sus valores pueden ser:
* S= habilitado.
* N= deshabilitado.';


--
-- TOC entry 1537 (class 1259 OID 90117)
-- Dependencies: 1536 6
-- Name: rol_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE rol_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.rol_id_seq OWNER TO stock;

--
-- TOC entry 1953 (class 0 OID 0)
-- Dependencies: 1537
-- Name: rol_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE rol_id_seq OWNED BY rol.id;


--
-- TOC entry 1954 (class 0 OID 0)
-- Dependencies: 1537
-- Name: rol_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('rol_id_seq', 5, true);


--
-- TOC entry 1538 (class 1259 OID 90122)
-- Dependencies: 6
-- Name: usuario; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE usuario (
    id bigint NOT NULL,
    login_usuario character varying NOT NULL,
    contrasenha character varying NOT NULL,
    nombre character varying NOT NULL,
    telefono character varying NOT NULL,
    nro_doc character varying NOT NULL,
    estado_civil character varying(1) NOT NULL,
    direccion character varying NOT NULL,
    id_rol bigint NOT NULL,
    apellido character varying,
    hab_inh character varying(1)
);


ALTER TABLE public.usuario OWNER TO stock;

--
-- TOC entry 1955 (class 0 OID 0)
-- Dependencies: 1538
-- Name: TABLE usuario; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE usuario IS 'En esta tabla se tiene que administrar los usuarios del Sistema.';


--
-- TOC entry 1956 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.id IS 'Identificador del Usuario';


--
-- TOC entry 1957 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.login_usuario; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.login_usuario IS 'Login Name del Usuario, es uno de los parámetros de las credenciales de acceso.';


--
-- TOC entry 1958 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.contrasenha; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.contrasenha IS 'Contraseña del Usuario, es el otro parámetro para acceder al Sistema.';


--
-- TOC entry 1959 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.nombre; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.nombre IS 'Nombre del Usuario.';


--
-- TOC entry 1960 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.telefono; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.telefono IS 'Telefono del Usuario.';


--
-- TOC entry 1961 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.nro_doc; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.nro_doc IS 'Nro. de Documento del Usuario.';


--
-- TOC entry 1962 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.estado_civil; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.estado_civil IS 'Sus valores pueden ser:
* S=Soltero/a.
* C=Casado/a.
* V=Viudo/a.
* D=Divorciado/a.';


--
-- TOC entry 1963 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.direccion; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.direccion IS 'Dirección del Usuario.';


--
-- TOC entry 1964 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.id_rol; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.id_rol IS 'Identificador del Rol Asociado.';


--
-- TOC entry 1965 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.apellido; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.apellido IS 'Apellido del Usuario.';


--
-- TOC entry 1966 (class 0 OID 0)
-- Dependencies: 1538
-- Name: COLUMN usuario.hab_inh; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN usuario.hab_inh IS 'Estado de Habilitación del Usuario.';


--
-- TOC entry 1539 (class 1259 OID 90128)
-- Dependencies: 1538 6
-- Name: usuario_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE usuario_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.usuario_id_seq OWNER TO stock;

--
-- TOC entry 1967 (class 0 OID 0)
-- Dependencies: 1539
-- Name: usuario_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE usuario_id_seq OWNED BY usuario.id;


--
-- TOC entry 1968 (class 0 OID 0)
-- Dependencies: 1539
-- Name: usuario_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('usuario_id_seq', 3, true);


--
-- TOC entry 1545 (class 1259 OID 90366)
-- Dependencies: 6
-- Name: venta; Type: TABLE; Schema: public; Owner: stock; Tablespace: 
--

CREATE TABLE venta (
    id bigint NOT NULL,
    id_producto_venta bigint NOT NULL,
    cantidad_venta bigint NOT NULL,
    monto_venta bigint NOT NULL,
    iva_10 double precision NOT NULL,
    id_cliente bigint NOT NULL,
    fecha_venta timestamp without time zone NOT NULL,
    id_usuario_vendedor bigint NOT NULL
);


ALTER TABLE public.venta OWNER TO stock;

--
-- TOC entry 1969 (class 0 OID 0)
-- Dependencies: 1545
-- Name: TABLE venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON TABLE venta IS 'En esta tabla se tiene que administrar las cabeceras de todas las ventas.';


--
-- TOC entry 1970 (class 0 OID 0)
-- Dependencies: 1545
-- Name: COLUMN venta.id; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.id IS 'Identificador de la Venta Cabecera.';


--
-- TOC entry 1971 (class 0 OID 0)
-- Dependencies: 1545
-- Name: COLUMN venta.id_producto_venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.id_producto_venta IS 'Identificador del Producto Vendido.';


--
-- TOC entry 1972 (class 0 OID 0)
-- Dependencies: 1545
-- Name: COLUMN venta.cantidad_venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.cantidad_venta IS 'Cantidad Vendida.';


--
-- TOC entry 1973 (class 0 OID 0)
-- Dependencies: 1545
-- Name: COLUMN venta.monto_venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.monto_venta IS 'Precio Grupal de todos los detalles.';


--
-- TOC entry 1974 (class 0 OID 0)
-- Dependencies: 1545
-- Name: COLUMN venta.iva_10; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.iva_10 IS 'Iva 10%';


--
-- TOC entry 1975 (class 0 OID 0)
-- Dependencies: 1545
-- Name: COLUMN venta.id_cliente; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.id_cliente IS 'Identificador del Cliente.';


--
-- TOC entry 1976 (class 0 OID 0)
-- Dependencies: 1545
-- Name: COLUMN venta.fecha_venta; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.fecha_venta IS 'Fecha de la Venta.';


--
-- TOC entry 1977 (class 0 OID 0)
-- Dependencies: 1545
-- Name: COLUMN venta.id_usuario_vendedor; Type: COMMENT; Schema: public; Owner: stock
--

COMMENT ON COLUMN venta.id_usuario_vendedor IS 'Identificador del Usuario Vendedor.';


--
-- TOC entry 1544 (class 1259 OID 90364)
-- Dependencies: 1545 6
-- Name: venta_id_seq; Type: SEQUENCE; Schema: public; Owner: stock
--

CREATE SEQUENCE venta_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.venta_id_seq OWNER TO stock;

--
-- TOC entry 1978 (class 0 OID 0)
-- Dependencies: 1544
-- Name: venta_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: stock
--

ALTER SEQUENCE venta_id_seq OWNED BY venta.id;


--
-- TOC entry 1979 (class 0 OID 0)
-- Dependencies: 1544
-- Name: venta_id_seq; Type: SEQUENCE SET; Schema: public; Owner: stock
--

SELECT pg_catalog.setval('venta_id_seq', 1, false);


--
-- TOC entry 1835 (class 2604 OID 90398)
-- Dependencies: 1547 1546 1547
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE auditoria_producto ALTER COLUMN id SET DEFAULT nextval('auditoria_producto_id_seq'::regclass);


--
-- TOC entry 1832 (class 2604 OID 90295)
-- Dependencies: 1540 1541 1541
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE cliente ALTER COLUMN id SET DEFAULT nextval('cliente_id_seq'::regclass);


--
-- TOC entry 1833 (class 2604 OID 90311)
-- Dependencies: 1543 1542 1543
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE compra ALTER COLUMN id SET DEFAULT nextval('compra_id_seq'::regclass);


--
-- TOC entry 1828 (class 2604 OID 90146)
-- Dependencies: 1533 1532
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE producto ALTER COLUMN id SET DEFAULT nextval('producto_id_seq'::regclass);


--
-- TOC entry 1829 (class 2604 OID 90147)
-- Dependencies: 1535 1534
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE proveedor ALTER COLUMN id SET DEFAULT nextval('proveedor_id_seq'::regclass);


--
-- TOC entry 1830 (class 2604 OID 90148)
-- Dependencies: 1537 1536
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE rol ALTER COLUMN id SET DEFAULT nextval('rol_id_seq'::regclass);


--
-- TOC entry 1827 (class 2604 OID 90142)
-- Dependencies: 1531 1530
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE tipo_producto ALTER COLUMN id SET DEFAULT nextval('categoria_id_seq'::regclass);


--
-- TOC entry 1831 (class 2604 OID 90149)
-- Dependencies: 1539 1538
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE usuario ALTER COLUMN id SET DEFAULT nextval('usuario_id_seq'::regclass);


--
-- TOC entry 1834 (class 2604 OID 90369)
-- Dependencies: 1545 1544 1545
-- Name: id; Type: DEFAULT; Schema: public; Owner: stock
--

ALTER TABLE venta ALTER COLUMN id SET DEFAULT nextval('venta_id_seq'::regclass);


--
-- TOC entry 1888 (class 0 OID 90428)
-- Dependencies: 1548
-- Data for Name: auditoria_cliente; Type: TABLE DATA; Schema: public; Owner: stock
--



--
-- TOC entry 1887 (class 0 OID 90395)
-- Dependencies: 1547
-- Data for Name: auditoria_producto; Type: TABLE DATA; Schema: public; Owner: stock
--

INSERT INTO auditoria_producto (id, id_producto, cantidad_anterior, cantidad_posterior, precio_anterior, precio_posterior, motivo) VALUES (1, 23, 15, 20, 10000, 7500, '0');
INSERT INTO auditoria_producto (id, id_producto, cantidad_anterior, cantidad_posterior, precio_anterior, precio_posterior, motivo) VALUES (2, 23, 15, 15, 10000, 10000, 'ACTUALIZACION');
INSERT INTO auditoria_producto (id, id_producto, cantidad_anterior, cantidad_posterior, precio_anterior, precio_posterior, motivo) VALUES (3, 23, 15, 23, 10000, 7500, 'ACTUALIZACION');
INSERT INTO auditoria_producto (id, id_producto, cantidad_anterior, cantidad_posterior, precio_anterior, precio_posterior, motivo) VALUES (4, 23, 15, 23, 10000, 7500, 'ACTUALIZACION');
INSERT INTO auditoria_producto (id, id_producto, cantidad_anterior, cantidad_posterior, precio_anterior, precio_posterior, motivo) VALUES (5, 23, 15, 23, 10000, 7500, 'ACTUALIZACION');


--
-- TOC entry 1884 (class 0 OID 90292)
-- Dependencies: 1541
-- Data for Name: cliente; Type: TABLE DATA; Schema: public; Owner: stock
--



--
-- TOC entry 1885 (class 0 OID 90308)
-- Dependencies: 1543
-- Data for Name: compra; Type: TABLE DATA; Schema: public; Owner: stock
--



--
-- TOC entry 1880 (class 0 OID 90095)
-- Dependencies: 1532
-- Data for Name: producto; Type: TABLE DATA; Schema: public; Owner: stock
--

INSERT INTO producto (id, codigo, nombre, id_tipo_producto, cantidad, precio, id_proveedor) VALUES (23, '12346556', 'YOUGURT 300ML', 17, 23, 7500, 5);


--
-- TOC entry 1881 (class 0 OID 90103)
-- Dependencies: 1534
-- Data for Name: proveedor; Type: TABLE DATA; Schema: public; Owner: stock
--

INSERT INTO proveedor (id, nombre, nombre_responsable, email_responsable, telefono_responsable) VALUES (5, 'TREBOL', 'RUBEN TROCHE', 'RUBENTROCHE@TREBOL.COM.PY', '(0981)123123');


--
-- TOC entry 1882 (class 0 OID 90111)
-- Dependencies: 1536
-- Data for Name: rol; Type: TABLE DATA; Schema: public; Owner: stock
--

INSERT INTO rol (id, nombre, descripcion, hab_inh) VALUES (3, 'Vendedor', 'Administra las Ventas.', 'S');
INSERT INTO rol (id, nombre, descripcion, hab_inh) VALUES (2, 'Catastrador', 'Administra Categorias, Productos, Cliente, Proveedor y Compra de Productos.', 'S');
INSERT INTO rol (id, nombre, descripcion, hab_inh) VALUES (1, 'Administrador', 'Administra los Usuarios, Roles y Permisos del Sistema', 'S');


--
-- TOC entry 1879 (class 0 OID 90066)
-- Dependencies: 1530
-- Data for Name: tipo_producto; Type: TABLE DATA; Schema: public; Owner: stock
--

INSERT INTO tipo_producto (id, nombre, descripcion) VALUES (17, 'Lacteos', 'Tipo de Producto Lacteos');


--
-- TOC entry 1883 (class 0 OID 90122)
-- Dependencies: 1538
-- Data for Name: usuario; Type: TABLE DATA; Schema: public; Owner: stock
--

INSERT INTO usuario (id, login_usuario, contrasenha, nombre, telefono, nro_doc, estado_civil, direccion, id_rol, apellido, hab_inh) VALUES (1, 'administrador', 'administrador', 'Marcelo', '096547895', '4776730', 'S', 'Luque km. 18', 1, NULL, NULL);
INSERT INTO usuario (id, login_usuario, contrasenha, nombre, telefono, nro_doc, estado_civil, direccion, id_rol, apellido, hab_inh) VALUES (2, 'catastrador', 'catastrador', 'Sanie Benitez', '0982707624', '3879564', 'S', 'luque km.18', 2, NULL, NULL);
INSERT INTO usuario (id, login_usuario, contrasenha, nombre, telefono, nro_doc, estado_civil, direccion, id_rol, apellido, hab_inh) VALUES (3, 'vendedor', 'vendedor', 'Ana Torres', '096157787', '3589456', 'S', 'Luque', 3, NULL, NULL);


--
-- TOC entry 1886 (class 0 OID 90366)
-- Dependencies: 1545
-- Data for Name: venta; Type: TABLE DATA; Schema: public; Owner: stock
--



--
-- TOC entry 1865 (class 2606 OID 90400)
-- Dependencies: 1547 1547
-- Name: auditoria_producto_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY auditoria_producto
    ADD CONSTRAINT auditoria_producto_pkey PRIMARY KEY (id);


--
-- TOC entry 1837 (class 2606 OID 90175)
-- Dependencies: 1530 1530
-- Name: categoria_nombre_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY tipo_producto
    ADD CONSTRAINT categoria_nombre_key UNIQUE (nombre);


--
-- TOC entry 1839 (class 2606 OID 90177)
-- Dependencies: 1530 1530
-- Name: categoria_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY tipo_producto
    ADD CONSTRAINT categoria_pkey PRIMARY KEY (id);


--
-- TOC entry 1857 (class 2606 OID 90302)
-- Dependencies: 1541 1541
-- Name: cliente_nro_doc_cliente_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY cliente
    ADD CONSTRAINT cliente_nro_doc_cliente_key UNIQUE (nro_doc);


--
-- TOC entry 1859 (class 2606 OID 90300)
-- Dependencies: 1541 1541
-- Name: cliente_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY cliente
    ADD CONSTRAINT cliente_pkey PRIMARY KEY (id);


--
-- TOC entry 1861 (class 2606 OID 90313)
-- Dependencies: 1543 1543
-- Name: compra_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY compra
    ADD CONSTRAINT compra_pkey PRIMARY KEY (id);


--
-- TOC entry 1867 (class 2606 OID 90451)
-- Dependencies: 1548 1548
-- Name: pk_auditoria_cliente; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY auditoria_cliente
    ADD CONSTRAINT pk_auditoria_cliente PRIMARY KEY (id);


--
-- TOC entry 1841 (class 2606 OID 90189)
-- Dependencies: 1532 1532
-- Name: producto_codigo_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT producto_codigo_key UNIQUE (codigo);


--
-- TOC entry 1843 (class 2606 OID 90191)
-- Dependencies: 1532 1532
-- Name: producto_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT producto_pkey PRIMARY KEY (id);


--
-- TOC entry 1845 (class 2606 OID 90193)
-- Dependencies: 1534 1534
-- Name: proveedor_nombre_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY proveedor
    ADD CONSTRAINT proveedor_nombre_key UNIQUE (nombre);


--
-- TOC entry 1847 (class 2606 OID 90195)
-- Dependencies: 1534 1534
-- Name: proveedor_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY proveedor
    ADD CONSTRAINT proveedor_pkey PRIMARY KEY (id);


--
-- TOC entry 1849 (class 2606 OID 90197)
-- Dependencies: 1536 1536
-- Name: rol_nombre_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY rol
    ADD CONSTRAINT rol_nombre_key UNIQUE (nombre);


--
-- TOC entry 1851 (class 2606 OID 90201)
-- Dependencies: 1536 1536
-- Name: rol_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY rol
    ADD CONSTRAINT rol_pkey PRIMARY KEY (id);


--
-- TOC entry 1853 (class 2606 OID 90203)
-- Dependencies: 1538 1538
-- Name: usuario_login_name_key; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT usuario_login_name_key UNIQUE (login_usuario);


--
-- TOC entry 1855 (class 2606 OID 90205)
-- Dependencies: 1538 1538
-- Name: usuario_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT usuario_pkey PRIMARY KEY (id);


--
-- TOC entry 1863 (class 2606 OID 90371)
-- Dependencies: 1545 1545
-- Name: venta_cabecera_pkey; Type: CONSTRAINT; Schema: public; Owner: stock; Tablespace: 
--

ALTER TABLE ONLY venta
    ADD CONSTRAINT venta_cabecera_pkey PRIMARY KEY (id);


--
-- TOC entry 1878 (class 2620 OID 90448)
-- Dependencies: 1532 21
-- Name: producto_update_tr; Type: TRIGGER; Schema: public; Owner: stock
--

CREATE TRIGGER producto_update_tr
    AFTER UPDATE ON producto
    FOR EACH ROW
    EXECUTE PROCEDURE producto_update_tr();


--
-- TOC entry 1877 (class 2606 OID 90436)
-- Dependencies: 1541 1548 1858
-- Name: fk_auditoria_cliente_cliente; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY auditoria_cliente
    ADD CONSTRAINT fk_auditoria_cliente_cliente FOREIGN KEY (id_cliente) REFERENCES cliente(id);


--
-- TOC entry 1876 (class 2606 OID 90406)
-- Dependencies: 1547 1532 1842
-- Name: fk_auditoria_producto; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY auditoria_producto
    ADD CONSTRAINT fk_auditoria_producto FOREIGN KEY (id_producto) REFERENCES producto(id);


--
-- TOC entry 1871 (class 2606 OID 90330)
-- Dependencies: 1842 1543 1532
-- Name: fk_compra_producto_comprado; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY compra
    ADD CONSTRAINT fk_compra_producto_comprado FOREIGN KEY (id_producto_comprado) REFERENCES producto(id);


--
-- TOC entry 1872 (class 2606 OID 90335)
-- Dependencies: 1543 1538 1854
-- Name: fk_compra_usuario_catastrador; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY compra
    ADD CONSTRAINT fk_compra_usuario_catastrador FOREIGN KEY (id_usuario_catastrador) REFERENCES usuario(id);


--
-- TOC entry 1869 (class 2606 OID 90340)
-- Dependencies: 1532 1534 1846
-- Name: fk_producto_proveedor; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT fk_producto_proveedor FOREIGN KEY (id_proveedor) REFERENCES proveedor(id);


--
-- TOC entry 1868 (class 2606 OID 90325)
-- Dependencies: 1532 1530 1838
-- Name: fk_producto_tipo_producto; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY producto
    ADD CONSTRAINT fk_producto_tipo_producto FOREIGN KEY (id_tipo_producto) REFERENCES tipo_producto(id);


--
-- TOC entry 1870 (class 2606 OID 90414)
-- Dependencies: 1536 1538 1850
-- Name: fk_usuario_rol; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY usuario
    ADD CONSTRAINT fk_usuario_rol FOREIGN KEY (id_rol) REFERENCES rol(id);


--
-- TOC entry 1874 (class 2606 OID 90382)
-- Dependencies: 1541 1545 1858
-- Name: fk_venta_cliente; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY venta
    ADD CONSTRAINT fk_venta_cliente FOREIGN KEY (id_cliente) REFERENCES cliente(id);


--
-- TOC entry 1873 (class 2606 OID 90372)
-- Dependencies: 1532 1545 1842
-- Name: fk_venta_producto; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY venta
    ADD CONSTRAINT fk_venta_producto FOREIGN KEY (id_producto_venta) REFERENCES producto(id);


--
-- TOC entry 1875 (class 2606 OID 90387)
-- Dependencies: 1545 1538 1854
-- Name: fk_venta_vendedor; Type: FK CONSTRAINT; Schema: public; Owner: stock
--

ALTER TABLE ONLY venta
    ADD CONSTRAINT fk_venta_vendedor FOREIGN KEY (id_usuario_vendedor) REFERENCES usuario(id);


--
-- TOC entry 1894 (class 0 OID 0)
-- Dependencies: 6
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--

REVOKE ALL ON SCHEMA public FROM PUBLIC;
REVOKE ALL ON SCHEMA public FROM postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO PUBLIC;


-- Completed on 2012-05-03 17:42:00

--
-- PostgreSQL database dump complete
--

